#include "execute.h"

// Implementation of CExecuteGroup
CExecute::CExecute(ICommand execute, ICommand unexecute, const std::string& execinfo)
	: m_Execute(execute), m_Unexecute(unexecute), m_Execinfo(execinfo) {}

CExecute::~CExecute() {}

void CExecute::Execute() {
	m_Execute.execute();
}

void CExecute::Unexecute() {
	m_Unexecute.execute();
}

std::string CExecute::GetExecInfo() const {
	return m_Execinfo;
}


// Implementation of CExecuteGroup
CExecuteGroup::CExecuteGroup(const std::string& execinfo) : CExecute(nullptr, nullptr, execinfo) {}
CExecuteGroup::~CExecuteGroup() {}

void CExecuteGroup::AddExecution(CExecutePtr orig) {
	m_Execvec.push_back(orig);
}

void CExecuteGroup::Execute() {
	for(auto it = m_Execvec.begin() ; it != m_Execvec.end() ; it++) {
		(*it)->Execute();
	}
}

void CExecuteGroup::Unexecute() {
	for(auto it = m_Execvec.rbegin() ; it != m_Execvec.rend() ; it++) {
		(*it)->Execute();
	}
}

